package com.xzsoft.gdwz.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import xz.facade.user.model.Result;

import com.xzsoft.gdwz.model.Ccid;
import com.xzsoft.gdwz.services.CcidService;

@Controller
@RequestMapping("/ccidController")
public class CcidController {
	@Autowired
	private CcidService ccidService;
	/**
	 * 
	  * @Title checkMaterialClass 方法名
	  * @Description 验证物资类
	  * @param request
	  * @param response
	  * @throws Exception 设定文件
	  * @return void 返回类型
	 */
	@RequestMapping("/checkMaterialClass")
	public void checkMaterialClass(HttpServletRequest request,HttpServletResponse response) throws Exception{
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Content-type","text/html;charset=UTF-8");//这句话的意思，是告诉servlet用UTF-8转码，而不是用默认的ISO8859
		Result result = new Result();
		JSONObject returnJO = new JSONObject();
		String data = request.getParameter("data");
		Ccid ccid = (Ccid)JSONObject.toBean(JSONObject.fromObject(data), Ccid.class);
		try {
			ccidService.checkMaterialClass(ccid);
			result.setResult("");
			result.setResultCode("");
			result.setResultMessage("成功！");
			result.setSuccess(true);
			returnJO = JSONObject.fromObject(result);
		} catch (Exception e) {
			e.printStackTrace();
			result.setResult("");
			result.setResultCode("C0012");
			result.setResultMessage(e.getMessage());
			result.setSuccess(false);
			returnJO = JSONObject.fromObject(result);
		}
		response.getWriter().write(returnJO.toString());
		response.getWriter().flush();  
		response.getWriter().close(); 
	}
	/**
	 * 
	  * @Title checkConstructionAndService 方法名
	  * @Description 验证施工和服务类
	  * @param request 
	  * @param response
	  * @throws Exception 设定文件
	  * @return void 返回类型
	 */
	@RequestMapping("/checkConstructionAndService")
	public void checkConstructionAndService(HttpServletRequest request,HttpServletResponse response) throws Exception{
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Content-type","text/html;charset=UTF-8");//这句话的意思，是告诉servlet用UTF-8转码，而不是用默认的ISO8859
		Result result = new Result();
		JSONObject returnJO = new JSONObject();
		String data = request.getParameter("data");
		Ccid ccid = (Ccid)JSONObject.toBean(JSONObject.fromObject(data), Ccid.class);
		try {
			ccidService.checkConstructionAndService(ccid);
			result.setResult("");
			result.setResultCode("");
			result.setResultMessage("成功！");
			result.setSuccess(true);
			returnJO = JSONObject.fromObject(result);
		} catch (Exception e) {
			e.printStackTrace();
			result.setResult("");
			result.setResultCode("C0012");
			result.setResultMessage(e.getMessage());
			result.setSuccess(false);
			returnJO = JSONObject.fromObject(result);
		}
		response.getWriter().write(returnJO.toString());
		response.getWriter().flush();  
		response.getWriter().close(); 
	}
}
